home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / docs / mags / AIOV55.lha / AIOIssue55 / examples / 2.4.0_malloc-free.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  608 b   |  17 lines

  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.   int * pointer1 = NULL;
  6.   int * pointer2 = NULL;
  7.  
  8.   pointer1 = (int *) malloc(100 * sizeof(int)); /* allocate 100 * sizeof(int) bytes */
  9.   pointer2 = (int *) calloc(100, sizeof(int));  /* allocate 100 ints */
  10.   if (pointer1) free(pointer1);    /* if pointer1 is non-zero, free it again */
  11.   else printf("Couldn't allocate memory for pointer1.\n"); /* otherwise an error occurred */
  12.   if (pointer2) free(pointer2);    /* if pointer2 is non-zero, free it again */
  13.   else printf("Couldn't allocate memory for pointer2.\n"); /* otherwise an error occurred */
  14.  
  15.   return 0;
  16. }
  17.